<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    request.setAttribute("path", path);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>地址管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" type="text/css" href="${path}/css/css.css"/>
    <link rel="stylesheet" type="text/css" href="${path}/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="${path}/css/menu.css"/>
    <link rel="stylesheet" type="text/css" href="${path}/css/address.css"/>
    <script type="text/javascript"
            src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="${path}/layer/layer.js" type="text/javascript"></script>
    <script src="${path}/js/main.js" type="text/javascript"></script>
    <script src="https://cdn.bootcss.com/distpicker/2.0.3/distpicker.js"></script>
    <title>地址</title>
    <script>
        //切换地址
        function updateAddress(t) {
            let addressId = $.trim(t.value);
            console.log(addressId)
            $.post("AddressServlet/updateDefault",{"addressId":addressId},function (data) {
                if (data==1){
                    location.reload();
                }
            },"text");
        }
        //添加地址
        function Address() {
            let province =$("#province option:selected").text();
            let city =$("#city option:selected").text();
            let district =$("#district option:selected").text();
            let describe =$("#describe").val();
            if (province.length<0||city.length<0||district.length<0||describe.length<0){
                layer.msg('请填取完整的地址');
            }else {
                $.post("AddressServlet/addAds",{"addressProvince":province,
                    "addressCity":city,"addressDistrict":district,"addressDescribe":describe
                },function (data) {
                    if (data==1){
                        location.reload();
                    }else {
                        layer.msg('添加失败');
                    }
                },"text");
            }

        }
        //提交订单
        function subOrder() {
           let address = $("#defAddress").text();
            if (address==null||address==""){
                layer.alert("请选择收货地址");
            }else {
                $.get("${path}/OrderServlet/submitOrder?address="+address,function (data) {
                    if (data==1){
                        alert("点单成功欢迎下次光临");
                        location.href="${path}/main.jsp";
                    }
                },"text");
            }
        }
    </script>
</head>

<body style="background:#F1F5F4">
<jsp:include page="top.jsp"></jsp:include>

<div class="m-address clear">
    <div class="wrapper">
        <div class="area clear" style="padding-left:20px">
            <!-- 送餐方式 -->
            配餐地址
            <div class="type clear">
                <c:forEach items="${requestScope.aList}" var="list">
                    <c:if test="${list.addressDefault =='Y'}">
                        <span id="defAddress" class="left"
                              style="width:400px;">${list.addressProvince}${list.addressCity}${list.addressDistrict}${list.addressDescribe}</span>
                    </c:if>

                </c:forEach>
                <select class=" rb-red" style="margin-right:10px" name="addressId" onchange="updateAddress(this)">
                    <option>-请选择-</option>
                <c:forEach items="${requestScope.aList}" var="list">
                    <option value="${list.addressId}">${list.addressProvince}${list.addressCity}${list.addressDistrict}${list.addressDescribe}</option>
                </c:forEach>
                </select>
                <span class="m-wt" style="padding: 0 30px"></span><a href="#" class=" rb-red"
                                                                     onclick="change('addaddress',3)">+使用新地址</a>
            </div>
            <%--  弹出新地址--%>
            <div style="display: none;" id="insert_addaddress" class="change">
                <div style="margin-top: 20px">
                    <span class="m-wt" style="padding: 0 30px"></span>
                    <div data-toggle="distpicker" style="margin-left: 120px">
                        <select id="province"></select>-<!-- 省 -->
                        <select id="city"></select>-<!-- 市 -->
                        <select id="district"></select>-<!-- 区 -->
                        <input type="text" id="describe" class="t-ad" style="width: 150px"/>
                    </div>
                </div>
                <div class="act-botton clear"
                     style="margin: 20px 40px; padding: 20px 0">
                    <div class="save-button">
                        <a href="javascript:" class="radius" onclick="Address()">保存</a>
                    </div>
                    <div class="cancel-button">
                        <a href="javascript:" class="radius"
                           onclick="change('addaddress',4)">取消</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="area">
            <div class="addr-box-line">
                <span class="text-w02 fl">顾客姓名</span>
                <span class="text-w02 fl">${user.userName}</span>
            </div>
            <div class="addr-box-line">
                <span class="text-w02 fl">联系电话</span>
                <span class="text-w02 fl" style="margin-left: 20px">${user.userTel}</span>
            </div>
            <div class="addr-box-line">
                <span class="text-w02 fr">总共金额</span>
                <span class="text-w02 fr"><span class="login-redcolor" style="font-size:24px">${sum}</span>元</span>
            </div>
            <div class="addr-box-line" id="j-address-reminder">
            </div>
            <div class="act-botton" id="j-act-botton" style="padding:10px 50px; ">
                <div style="padding:10px 50px; background:#DF544E; width:120px; text-align:center;
        border-radius:5px
       "><a href="javascript:" style="color:#FFF; font-size:22px;" onclick="subOrder()">提交订单 &gt;</a></div>
            </div>
        </div>
        <div class="area clear" style="margin-top:60px; font-size:14px; color:#999; padding-left:30px">
            友情提示：网络订餐不提供订单修改和取消功能，请提交前仔细核实订单内容
        </div>
    </div>


    <jsp:include page="foot.jsp"></jsp:include>
</div>
</body>
</html>
<SCRIPT Language=VBScript><!--

//-->
</SCRIPT>